package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.domain.CmsSubject;
import com.itheima.mapper.CmsSubjectMapper;
import com.itheima.service.CmsSubjectService;
import com.itheima.util.PageBean;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 专题表 服务实现类
 * </p>
 *
 * @author zhuguo
 * @since 2022-11-10
 */
@DubboService
public class CmsSubjectServiceImpl extends ServiceImpl<CmsSubjectMapper, CmsSubject> implements CmsSubjectService {

    @Override
    public PageBean pageInfo(String keyword, Integer pageNum, Integer pageSize) {
        PageBean pageBean = new PageBean();
        LambdaQueryWrapper<CmsSubject> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(keyword!=null,CmsSubject::getCategoryName, keyword);
        List<CmsSubject> list = list(queryWrapper);
        Integer count = count(queryWrapper);
        int totalPage = (count + pageSize - 1) / pageSize;
        pageBean.setList(list);
        pageBean.setPageNum(pageNum);
        pageBean.setPageSize(pageSize);
        pageBean.setTotal(count);
        pageBean.setTotalPage(totalPage);
        return pageBean;
    }
}
